import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    redirect: '/message',
    component: () => import('../views/Home.vue'),
    children: [
      {
        path: '/message',
        name: 'message',
        title: '消息队列',
        component: () => import('../components/page/message.vue'),
      },
      {
        path: '/file',
        name: 'file',
        title: '离线文件',
        component: () => import('../components/page/file.vue'),
      }
    ]
  },
]
const router = new VueRouter({
  routes
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
export default router
